/**
 * 
 */
package org.huanglei.account.view.adapter;

import java.util.List;

import org.huanglei.account.R;
import org.huanglei.account.bean.Account;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * @author huanglei
 * @data Jul 10, 2012
 */
public class AccountListAdapter extends BaseAdapter {

	private final Context context;

	private final List<Account> accounts;

	public AccountListAdapter(Context context, List<Account> accounts) {
		this.context = context;
		this.accounts = accounts;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount() {
		return accounts.size();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int position) {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int position) {
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getView(int, android.view.View,
	 * android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View view, ViewGroup viewGroup) {
		view = LayoutInflater.from(context).inflate(R.layout.account_list_item,
				null);
		
		// 类型
		TextView tvId = (TextView) view.findViewById(R.id.account_list_item_id);
		tvId.setText(String.valueOf(accounts.get(position).getId()));
		
		TextView tvType = (TextView) view
				.findViewById(R.id.account_list_item_type);
		tvType.setText(accounts.get(position).getType());
		
		// 金额
		TextView tvMoney = (TextView) view
				.findViewById(R.id.account_list_item_money);
		tvMoney.setText(""+accounts.get(position).getMoney());
		
		// 日期
		TextView tvDate = (TextView) view
				.findViewById(R.id.account_list_item_date);
		tvDate.setText(accounts.get(position).getDateString());
		
		// 简介
		TextView tvMemo = (TextView) view
				.findViewById(R.id.account_list_item_memo);
		tvMemo.setText(accounts.get(position).getMemo());
		
		return view;
	}
}
